package org.oschina.api;

import java.io.File;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.multipart.MultipartFile;

public class BaseController {
	
	private final static Logger logger=LoggerFactory.getLogger(BaseController.class);

	private HttpServletRequest request;
	private HttpServletResponse response;

	public HttpServletRequest getRequest() {
		return request;
	}
	public HttpServletResponse getResponse() {
		return response;
	}
	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}
	public void setResponse(HttpServletResponse response) {
		this.response = response;
	}

	/**
	 * 设置属性
	 * @param name
	 * @param value
	 */
	protected void setAttribute(String name,Object value)
	{
		request.setAttribute(name, value);
	}
	
	/**
	 * 转换为File
	 * @param file
	 * @return
	 */
	protected File toFile(MultipartFile multipartFile)
	{
		try
		{
			File file=new File(multipartFile.getOriginalFilename());
			multipartFile.transferTo(file);
			return file;
		}
		catch(Exception e)
		{
			logger.error("",e);
			return null;
		}
	}
}